﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace sXNAke
{
    public enum Direction { LEFT, RIGHT, UP, DOWN, NONE }
    class Util
    {
        /// <summary>
		/// Convert degrees ijnto radians
		/// @param	degrees -> a value to be converteds
		/// @return the correspond radian value
		/// <summary>
		public static float convertDegreesToRadians(float degrees)
		{
			return (float)(degrees * ( Math.PI/ 180f));
        }
		
		/// <summary>
		/// Convert Radians to degrees
		/// @param	radians -> a value to convert
		/// @return the correspond degrees value
		/// <summary>
		public static float convertRadiansToDegrees(float radians)
		{
            return (float)((radians * 180) / Math.PI);
		}

        public static bool isNull(object T)
        {
            if (T != null)
                return false;

            return true;
        }

        public static Vector2 getDirectionAngle(Vector2 u, Vector2 v)
        {
            Vector2 r = v - u;
            float mU = (float)Math.Sqrt((u.X * u.X) + (u.Y * u.Y));
            float mV = (float)Math.Sqrt((v.X * v.X) + (v.Y * v.Y));
            if (mU == 0)
                mU = 1;
            if (mV == 0)
                mV = 1;
            float b = mU * mV;
            if (r.X >= 0.5f)
            {
                r.X = (float)Math.Ceiling(r.X / b);
            }
            else
            {
                r.X = (float)Math.Floor(r.X / b);
            }
            if (r.Y >= 0.5f)
            {
                r.Y = (float)Math.Ceiling(r.Y / b);
            }
            else
            {
                r.Y = (float)Math.Floor(r.Y / b);
            }
            return new Vector2(r.X, r.Y);
        }
        public static Vector2 getDirection(Vector2 u)
        {
            u.Normalize();
            float x = (float)(Math.Floor(u.X));
            float y = (float)(Math.Floor(u.Y));
            return new Vector2(x, y);
        }
    }
}
